﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class MyLy_MylyInformationp : System.Web.UI.Page
{
    BLL.UserBean bean = new UserBean();
    WebUtility utility = new WebUtility();
    DataTable table = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.birth.Attributes.Add("onfocus", "WdatePicker({skin:'ext',dateFmt:'yyyy-MM-dd'})");

        if (!IsPostBack)
        {
            ddl_Vocation.Items.Insert(0, new ListItem("----请选择----"));
            WebUtility.BindList("行业属性", ddl_Vocation);
            WebUtility.BindList("文化程度代码", ddl_Education);

            string mobile = "";
            if (Session["LoginUser"] == null)
            {
                Response.Redirect(WebUtility.getWebRootPath() + "/Login/Login.aspx");
            }
            else
            {
                mobile = Session["LoginUser"].ToString();
                table = bean.getRegUsetDetials(mobile);

                if (table.Rows.Count > 0)
                {
                    this.mobilePhone.Text = table.Rows[0]["LoginID"].ToString();
                    this.realName.Text = table.Rows[0]["LXRXXB_XM"].ToString();
                    string sex = table.Rows[0]["LXRXXB_XQAH"].ToString();
                    if (sex.Equals("女"))
                    {
                        this.Rbrn_Girl.Checked = true;
                    }
                    else
                    {
                        this.Rbtn_Man.Checked = true;
                    }
                    this.phone.Text = table.Rows[0]["LXRXXB_GSDH"].ToString();
                    this.email.Text = table.Rows[0]["EMail"].ToString();
                    if (table.Rows[0]["LXRXXB_ZY"].ToString() == "")
                    {
                        this.ddl_Vocation.SelectedIndex = 0;
                    }
                    else
                    {
                        this.ddl_Vocation.SelectedItem.Text = table.Rows[0]["LXRXXB_ZY"].ToString();
                    }
                    this.address.Text = table.Rows[0]["LXRXXB_JTDZ"].ToString();
                    this.zipCode.Text = table.Rows[0]["LXRXXB_YB"].ToString();
                    if (table.Rows[0]["LXRXXB_WHCD"].ToString() == "")
                    {
                        this.ddl_Education.SelectedIndex = 0;
                    }
                    else
                    {
                        this.ddl_Education.SelectedItem.Text = table.Rows[0]["LXRXXB_WHCD"].ToString();
                    }
                    this.birth.Text = Convert.ToDateTime(table.Rows[0]["LXRXXB_CSNY"].ToString()).ToShortDateString();
                    this.hobby.Text = table.Rows[0]["LXRXXB_XQAH"].ToString();
                }
            }
        }
    }

    protected void ImgBtn_Modify_Click(object sender, ImageClickEventArgs e)
    {
        string mobileNO = this.mobilePhone.Text;
        string name = this.realName.Text;
        string sex = this.Rbtn_Man.Checked ? Rbtn_Man.Text : Rbrn_Girl.Text;
        string phone = this.phone.Text;
        string email = this.email.Text;
        string vocation = this.ddl_Vocation.SelectedIndex != 0 ? this.ddl_Vocation.SelectedItem.Text : "";
        string address = this.address.Text;
        string zipCode = this.zipCode.Text;
        string education = this.ddl_Education.SelectedIndex != 0 ? this.ddl_Education.SelectedItem.Text : "";
        string birth = this.birth.Text;
        string hobby = this.hobby.Text;
        
        int count = bean.updateRegUserDetails(mobileNO, name, sex, phone, email, vocation, address, zipCode, education, birth, hobby);
        if (count > 0)
        {
            utility.AlertMsg("信息修改成功！");
        }
        else
        {
            utility.AlertMsg("信息修改！");
            return;
        }
    }
}
